#include <stdio.h>
#include <stdlib.h>

typedef struct ActivityNode *Activities;
struct ActivityNode {
    int start; /* 开始时间 */
    int finish; /* 结束时间 */
};

int CmpFinish(const void *a, const void *b) {
    return (((const struct ActivityNode*)a)->finish > ((const struct ActivityNode*)
            b)->finish) ? 1 : -1;
}

/* 算法15-11：活动安排问题的贪心算法 ActivitySelection(a, k, n) */
int ActivitySelection(Activities a, int k, int n) {
    /* a[k] 是最新被收录进最优解的活动 */
    int i;

    /* 寻找开始时间在a[k]结束之后的、最早结束的活动 */
    for (i = k + 1; i <= n; i++) {
        if (a[i].start >= a[k].finish) {
            break;
        }
    }
    if (i <= n) {
        return (1 + ActivitySelection(a, i, n));
    } else {
        return 0;
    }
}
/* 算法15-11 结束 */

int main(void) {
    Activities a;
    int n, i;

    scanf("%d", &n);
    a = (Activities)malloc(sizeof(struct ActivityNode) * (n + 1));
    a[0].finish = 0; /* a[0] 是一个虚设的活动，其结束时间为 0 */
    a[0].start = 0;
    for (i = 1; i <= n; i++) {
        scanf("%d", &a[i].start);
    }
    for (i = 1; i <= n; i++) {
        scanf("%d", &a[i].finish);
    }
    qsort(a, n + 1, sizeof(struct ActivityNode), CmpFinish);
    printf("%d", ActivitySelection(a, 0, n));

    return 0;
}